import { Toast } from "vant";
import bridge from "./dsbridge.js";
import { getValue, setValue, setObject } from "@/utils/auth";
import {getHandle} from "../api";
export function getUrlKey(name) {
  // eslint-disable-next-line no-sparse-arrays
  return (
    decodeURIComponent(
      (new RegExp("[?|&]" + name + "=" + "([^&;]+?)(&|#|;|$)").exec(
        location.href
      ) || [, ""])[1].replace(/\+/g, "%20")
    ) || null
  );
}
export function isJsonString(str) {
  try {
    if (typeof JSON.parse(str) === "object") {
      return true;
    }
  } catch (e) {
    console.error(e);
  }
  return false;
}
// 工作流页面跳转
export const goPage = (data) => {

  console.log(data)
  let page = "";
  if (
    data.flowId == "ReceiveReportCY" ||
    data.flowId == "ReceiveReportCDZBZC"
  ) {
    setValue("ysdObj", JSON.stringify(data));
  } else {
    setValue("wyObj", JSON.stringify(data));
  }

  setValue("isExhibition", "");
  var flowId = data.flowId;
  if ("fapiaoguanli" == flowId) {
    page = "invoiceDetails";
  } else if ("DepositCheckReturn" == flowId) {
    page = "depositRefundDetail";
  } else if ("ProjectActiveInfo" == flowId) {
    page = "projectActivationManage";
  } else if ("fapiaozuofeishenqing" == flowId) {
   // Toast("正在维护中");
  } else if ("weiyueguanli" == flowId) {
    page = "breakContractManageDetails";
  } else if ("LeadProgramInfo" == flowId) {
    // TODO:安卓姐添加
    if (
      data.businessType === "bao_jie" ||
      data.businessType === "can_yin" ||
      data.businessType === "guang_gao" ||
      data.businessType === "wu_zi"
    ) {
      page = "leadingProgramOther";
    }
    if (data.businessType === "an_bao") {
      page = "leadingProgramAnbao";
    }
    if (data.businessType === "hui_yi") {
      page = "leadingProgramHuiyi";
    }
    if (data.businessType === "mei_ti_xuan_chuan") {
      page = "leadingProgramMeiti";
    }
    if (data.businessType === "she_bei") {
      page = "leadingProgramShebei";
    }
    if (data.businessType === "ting_che_chang") {
      page = "leadingProgramTingchechang";
    }
  } else if ("SiteOrder" == flowId) {
    page = "SiteAppointmentDetails";
    setValue("site-isEdit", "");
  } else if ("ExhibitionSummaryForSubProject" == flowId) {
    var businessType = data.businessType;
    setValue(
      "exhibition-summary-part",
      JSON.stringify({
        source: "part",
        code: businessType,
      })
    );
    page = "exhibitionSummaryDetailsPart";
  }

  else if ("ExhibitionSummaryForSubProjectBJ" == flowId) {//保洁
    var businessType = data.businessType;
    setValue(
      "exhibition-summary-part",
      JSON.stringify({
        source: "part",
        code: businessType,
      })
    );
    page = "exhibitionSummaryDetailsPart";
  }
  else if ("ExhibitionSummaryForSubProjectCY" == flowId) {//餐饮
    var businessType = data.businessType;
    setValue(
      "exhibition-summary-part",
      JSON.stringify({
        source: "part",
        code: businessType,
      })
    );
    page = "exhibitionSummaryDetailsPart";
  }



  else if ("CateringMealApply" == flowId) {
    page = "restaurantApplyMealDetail";
  } else if ("ExhibitionSummary" == flowId) {
  } else if ("waiyuanshenqing" == flowId) {
    page = "externalApplicationAdd";
  } else if ("WeMediaRelease" == flowId) {
    page = "weMediaPublishDetail";
  } else if ("ActivityBooking" == flowId) {
    page = "meetingReservationDetail";
  } else if ("FinalStatementGGNYF" == flowId) {
    page = "exhibitionAccountsDetails";
    setValue(
      "exhibition-accounts-manage",
      JSON.stringify({
        code: data.businessType,
        name: "待办",
      })
    );
    // if ('guang_gao'.equals(businessType)) {
    // } else if ('nuan_tong'.equals(businessType)) {
    // } else if ('wu_zi'.equals(businessType)) {
    // } else if ('an_bao'.equals(businessType)) {
    // } else if ('ren_shi_kao_he'.equals(businessType)) {
    // }
  } else if ("ReceiveReportCDZBZC" == flowId) {
    page = "exhibitionReceiptManageDetails";
  } else if ("ReceiveReportGG" == flowId) {
  } else if ("ReceiveReportCY" == flowId) {
    page = "exhibitionReceiptManageDetails";
  } else if ("FinalStatementSTJT" == flowId) {
    setValue(
      "exhibition-accounts-manage",
      JSON.stringify({
        code: "si_tu_jia_te",
        name: "斯图加特",
      })
    );
  } else if ("CleaningStatement" == flowId) {
    setValue(
      "exhibition-accounts-manage",
      JSON.stringify({
        code: "bao_jie",
        name: "保洁",
      })
    );
    page = "exhibitionAccountsDetails";
  } else if ("OutsourceUnitAsmOrg" == flowId) {
  } else if ("SpecialEquipmentApply" == flowId) {
    page = "specialEquipmentApplicantDetails";
  } else if ("OfficeSupplies" == flowId) {
    setValue(
      "exhibition-accounts-manage",
      JSON.stringify({
        code: "hou_qin",
        name: "办公用品结算单",
      })
    );
    page = "exhibitionAccountsDetails";
  } else if ("LaborCost" == flowId) {
  } else if ("DataSubmit" == flowId) {
  } else if ("OutsourceUnitAsmRm" == flowId) {
  } else if ("WeMediaCommunicate" == flowId) {
  } else if ("ProjectSupervisionInfo" == flowId) {
    page = "projectSupervision";
  } else if ("DataArchive" == flowId) {
    page = "exhibitionPigeonholeManage";
  } else if ("DataArchiveLater" == flowId) {
    page = "delayArchiveDetails";
  } else if ("OfficeSuppliesInfo" == flowId) {
    page = 'officeSuppliesRequisitionedDetail'
  } else if ("DailyAdvertApply" == flowId) {
    page = "dailyAdvertiserDetail";
  } else if ("SpecialEquipmentUse" == flowId) {
    page = "specialEquipmentRecipientsDetails";
  } else if ("DailyAdvertFinal" == flowId) {
    page = "advertisingQuarterDetail";
  } else if ("SpecialEquipmentVerfiy" == flowId) {
    page = "specialEquipmentAcceptanceDetail";
  } else if ("waiyuanziliucheng" == flowId) {
  } else if ("ActivityTempChange"==flowId) {//临时变更单详情
    page = "huiyiLinshiChange";
  }
  else if ("ActivityReceptionPlan"==flowId) {
    page ="jiedaiPlanProcess"

  }
  else if ("ActivityContractInfo"==flowId) {
    page ="contractualActivity"

  }
  else if ("OrderBusApply"==flowId) {
    // getHandle('/venues/api/exhibitionManage/orderbus/queryDetail', {id: data.businessId}).then(res=> {
    //   let obj = res.body.data
    //   setValue('zgOrderItem', JSON.stringify(obj))
    //   setValue("type", "view");
    //   setValue("exhibitionId", obj.exhibitionInfoId);
    //   // 所有的工作流都是这样写
    //   setValue("optType", "view");
    //   setValue("busServicesType", "view");
    //   setValue("processInstanceStatus", obj.processInstanceStatus);
    //   setValue("trackId", obj.trackId);
    //   setValue("workId", obj.workId);
    //   setValue("flowId", obj.flowId);
    //   setValue("runTimeTaskName", obj.runTimeTaskName);
    //   if (obj.processInstanceStatus === 'END') {
    //     // bridge.call('exhibitionZgOrderManageDetails')
    //     if (process.env.NODE_ENV === "development") {
    //       bridge.call('exhibitionZgOrderManageDetails');
    //     } else {
    //       data['page'] = 'exhibitionZgOrderManageDetails'
    //       bridge.call("allItemSpd", data);
    //     }
    //   } else {
    //     setValue("zgOrderItemCode", obj.itemCode);
    //     setValue("busServicesType", "view");
    //     setValue("busServicesList", "");
    //     // bridge.call("busServices");
    //     if (process.env.NODE_ENV === "development") {
    //       bridge.call('busServices');
    //     } else {
    //       data['page'] = 'busServices'
    //       bridge.call("allItemSpd", data);
    //     }
    //   }
    // })
    page='busServices'

  }
  else if ("OrderMeetingApply"==flowId) {
    // getHandle('/venues/api/exhibitionManage/order/queryDetail', {id: data.businessId, itemCode: 'MEETING_ROOMS'}).then(res=>{
    //   let obj = res.body.orderInfo
    //   setValue('zgOrderItem', JSON.stringify(obj))
    //   setValue("type", "view");
    //   setValue("exhibitionId", obj.exhibitionInfoId);
    //   // 所有的工作流都是这样写
    //   setValue("optType", "view");
    //   setValue("meetingRoomsServicesType", "view");
    //   setValue("processInstanceStatus", obj.processInstanceStatus);
    //   setValue("trackId", obj.trackId);
    //   setValue("workId", obj.workId);
    //   setValue("flowId", obj.flowId);
    //   setValue("runTimeTaskName", obj.runTimeTaskName);
    //   setValue("meetingRoomsServicesType", "view");
    //   setValue("meetingRoomsServicesList", "");
    //   if(obj.processInstanceStatus==='END'){
    //     // bridge.call('exhibitionZgOrderManageDetails')
    //     if (process.env.NODE_ENV === "development") {
    //       bridge.call('exhibitionZgOrderManageDetails');
    //     } else {
    //       data['page'] = 'exhibitionZgOrderManageDetails'
    //       bridge.call("allItemSpd", data);
    //     }
    //   }else{
    //     setValue("zgOrderItemCode", obj.itemCode);
    //     // bridge.call("meetingRoomsServices");
    //     if (process.env.NODE_ENV === "development") {
    //       bridge.call('meetingRoomsServices');
    //     } else {
    //       data['page'] = 'meetingRoomsServices'
    //       bridge.call("allItemSpd", data);
    //     }
    //   }
    // })
    setValue("zgOrderItemCode", 'MEETING_ROOMS');
    page ="meetingRoomsServices"

  }
   else if ("WalkieTalkieUseRe"==flowId) {
     debugger

    page ="duijiangjiApplicantDetails"

  }
  else if ("WalkieTalkieReturnRe"==flowId) {
    page ="duijiangjiExitDetails"

  }
  else {
    //Toast("正在维护");
  }
  if (process.env.NODE_ENV === "development") {
    bridge.call(page);
  } else {
    bridge.call("allItemSpd", data);
  }
};

export function filePreview(d) {
  var url = "";
  var server = process.env.VUE_APP_FILE_SERVER_API;
  var fileIP = process.env.VUE_APP_FILE_IP_API;
  var previewServer = process.env.VUE_APP_PREVIEW_SERVER;
  var url_online_preview = previewServer + "/preview/onlinePreview?url=";
  var url_file_server = fileIP + "/fms/api/download";
  var imgFileTypeList = [
    ".PNG",
    ".png",
    ".jpg",
    ".JPG",
    ".bmp",
    ".jpeg",
    ".JPEG",
  ];
  var otherFileTypeList = [
    ".doc",
    ".docx",
    ".xls",
    ".xlsx",
    ".ppt",
    ".pptx",
    ".pdf",
    ".txt",
  ];
  // if (imgFileTypeList.indexOf(d.regex) >= 0) {
  //   url = server + '/fms/api/show/' + d.fileId + '_c'
  //   console.log(url)
  //   bridge.call('base.openWebImgUrl', url)
  // } else
  if (
    otherFileTypeList.indexOf(d.regex) >= 0 ||
    imgFileTypeList.indexOf(d.regex) >= 0
  ) {
    var params = encodeURIComponent(
      url_file_server + "/" + d.fileId + "?fullfilename=" + d.fileId + d.regex
    );
    console.log(
      url_file_server + "/" + d.fileId + "?fullfilename=" + d.fileId + d.regex
    );
    url = url_online_preview + params;
    console.log(url);
    bridge.call("base.openWebUrl", url);
  } else {
    Toast("该文件不支持预览！");
  }
}
// 获取当前时间格式化
export const getNowFormatDate1 = (msg) => {
  // 时间格式化
  var date = "";
  if (msg) {
    var date = new Date(msg);
  } else {
    var date = new Date();
  }
  var seperator1 = "-";
  var seperator2 = ":";
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  var minute = date.getMinutes();
  var second = date.getSeconds();
  var hours = date.getHours();

  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  if (minute >= 0 && minute <= 9) {
    minute = "0" + minute;
  }
  if (second >= 0 && second <= 9) {
    second = "0" + second;
  }
  if (hours >= 0 && hours <= 9) {
    hours = "0" + hours;
  }
  var currentdate =
    date.getFullYear() +
    seperator1 +
    month +
    seperator1 +
    strDate +
    " " +
    hours +
    seperator2 +
    minute;
  return currentdate;
};
// http://ylclouds.nat100.top/preview/onlinePreview?url=http%3A%2F%2F10.176.4.178%3A8083%2Ffms%2Fapi%2Fdownload%2Faa730a30-ab01-45f6-9c54-5f6901bff75f%3Ffullfilename%3Daa730a30-ab01-45f6-9c54-5f6901bff75f.xlsx
